package com.cg.ggkt.vod.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cg.ggkt.vod.mapper.TeacherMapper;
import com.cg.ggkt.vod.service.ITeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cg.ggkt.model.vod.Teacher;
import com.cg.ggkt.vo.vod.TeacherQueryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author caigang
 * @since 2022-07-20
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {

    @Override
    public IPage<Teacher> findQueryPage(long current, long limit, TeacherQueryVo vo) {
        Page<Teacher> page = new Page<>(current,limit);
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        if(vo == null) return this.page(page);
        if(!StringUtils.isEmpty(vo.getName())){
            queryWrapper.eq("name", vo.getName().trim());
        }
        if(vo.getLevel() != null){
            queryWrapper.eq("level", vo.getLevel());
        }
        if(!StringUtils.isEmpty(vo.getJoinDateBegin())){
            queryWrapper.ge("join_date", vo.getJoinDateBegin().trim());
        }
        if(!StringUtils.isEmpty(vo.getJoinDateEnd())){
            queryWrapper.le("join_date", vo.getJoinDateEnd().trim());
        }
        return this.page(page, queryWrapper);
    }
}
